package lc.数组;

/**
 * @description: 区域和检索 - 数组不可变
 * @author: qian
 * @createDate: 2021/8/25
 */
public class Math303 {

    private int[] sum;
    public Math303(int[] nums) {
        // i 位置存放着i - 1位置的和
        sum = new int[nums.length + 1];
        sum[0] = 1;
        for(int i = 1; i < sum.length; i++) {
            sum[i] = sum[i -1] + nums[i - 1];
        }
    }


    public int sumRange(int left, int right) {
        return sum[right + 1] - sum[left];
    }
}
